﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RoleAdmin.aspx.cs" Inherits="MemberMgr.Website.Admin.RoleAdmin" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        var onNodeChange = function(node, checked) {
            if (node.isLeaf()) {
                if (checked) {
                    
                }
            } else {
                /*
                node.eachChild(function(item, index, allitems) {
                    if (item.getUI().isChecked() != checked) {
                        item.getUI().toggleCheck(checked);
                    }
                });
                */
            }
        };

        var onTreeSubmit = function() {
            hidFunno.setValue('');
            var selNodes = menuTree.getChecked();

            Ext.each(selNodes, function(node) {

                if (hidFunno.getValue().indexOf(node.attributes.funno + ',') == -1) {
                    hidFunno.setValue(hidFunno.getValue() + node.attributes.funno + ',');

                    if (node.isLeaf()) {
                        if (hidFunno.getValue().indexOf(node.parentNode.attributes.funno + ',') == -1) {
                            hidFunno.setValue(hidFunno.getValue() + node.parentNode.attributes.funno + ',');
                        }
                    }
                }
            });
        }

        var onAterSuccess = function() {
            CheckTree(menuTree.root, hidFunno.getValue());
        }

        function CheckTree(node, right) {
        
            
            if (right.indexOf(node.attributes.funno + ',') != -1) {
                node.getUI().toggleCheck(true);
            }
            else
            {
                node.getUI().toggleCheck(false);
            }

            node.eachChild(function(currentnode) {
                if (currentnode.isLeaf()) {
                    if (right.indexOf(currentnode.attributes.funno + ',') != -1) {
                        currentnode.getUI().toggleCheck(true);
                    }
                    else {
                        currentnode.getUI().toggleCheck(false);
                    }
                }
                else {
                    CheckTree(currentnode, right);
                }
            });
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server" Locale="zh-CN" />
    <ext:Store ID="roleStore" runat="server" OnRefreshData="roleStore_RefreshData">
        <Reader>
            <ext:JsonReader IDProperty="ID">
                <Fields>
                    <ext:RecordField Name="ROLENAME" />
                    <ext:RecordField Name="ROLEATTR" />
                    <ext:RecordField Name="COMMENT" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Viewport ID="Viewport1" runat="server" Layout="border">
        <Items>
            <ext:FormPanel ID="FormPanel1" runat="server" Region="North" Title="查询条件" Padding="5"
                Height="100" Frame="true" Margins="5 5 5 5" Layout="Table" Icon="Magnifier">
                <Items>
                    <ext:TableLayout ID="tblLayout" runat="server" Columns="4" LabelWidth="70" LabelAlign="Right">
                        <Cells>
                            <ext:Cell ColSpan="4">
                                <ext:TextField ID="txtSearchName" runat="server" Text="" FieldLabel="角色名称">
                                </ext:TextField>
                            </ext:Cell>
                        </Cells>
                    </ext:TableLayout>
                </Items>
                <Buttons>
                    <ext:Button ID="btnSearch" Type="Button" runat="server" Text=" 查 询 ">
                        <DirectEvents>
                            <Click OnEvent="btnSearch_Click" DisableCaching="true">
                                <EventMask ShowMask="true" Msg="正在查询，请稍后..." />
                            </Click>
                        </DirectEvents>
                    </ext:Button>
                </Buttons>
            </ext:FormPanel>
            <ext:GridPanel ID="gpRoles" runat="server" StoreID="roleStore" Title="角色信息" AutoExpandColumn="Comment"
                Margins="0 5 5 5" Region="Center" Frame="true">
                <TopBar>
                <ext:Toolbar ID="tblGrid" runat="server">
                    <Items>
                        <ext:Button ID="btnAdd" runat="server" Text="添加角色" Icon="Add">
                            <Listeners>
                                <Click Handler="#{panelDetail}.getForm().reset();#{winRoleDetail}.show();" />
                            </Listeners>
                        </ext:Button>
                        
                        <ext:Button ID="btnDelete" runat="server" Text="删除角色" Icon="Exclamation">
                            <DirectEvents>
                                <Click OnEvent="btnDelete_Click">
                                    <EventMask ShowMask="true" Msg = "数据保存中，请稍后..."  />
                                    <Confirmation ConfirmRequest="true"  Message="确认删除选中的记录吗？" Title="删除确认" />
                                    <ExtraParams>
                                        <ext:Parameter Name="roleid" Value="#{gpRoles}.getSelectionModel().getSelected().id" Mode="Raw"></ext:Parameter>
                                    </ExtraParams>
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </TopBar>
                <ColumnModel ID="cmRoles" runat="server">
                    <Columns>
                        <ext:RowNumbererColumn />
                        <ext:Column Header="角色名称" Width="100" DataIndex="ROLENAME">
                        </ext:Column>
                        <ext:Column Header="角色属性" Width="150" DataIndex="ROLEATTR">
                        </ext:Column>
                        <ext:Column ColumnID="Comment" Header="备注" Width="150" DataIndex="COMMENT">
                        </ext:Column>
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:RowSelectionModel ID="rowSelModeNote" runat="server" />
                </SelectionModel>
                <LoadMask ShowMask="true" />
                <BottomBar>
                    <ext:PagingToolbar ID="pageTool" runat="server" PageSize="10" StoreID="roleStore" />
                </BottomBar>
                <DirectEvents>
                    <RowDblClick OnEvent="roleGrid_RowDbClick" Success="onAterSuccess">
                        <EventMask ShowMask="true" Target="CustomTarget" CustomTarget="#{gpRoles}" Msg="正在加载数据,请稍后..." />
                        <ExtraParams>
                            <ext:Parameter Name="roleid" Value="this.getSelectionModel().getSelected().id" Mode="Raw">
                            </ext:Parameter>
                        </ExtraParams>
                    </RowDblClick>
                </DirectEvents>
            </ext:GridPanel>
        </Items>
    </ext:Viewport>
    <ext:Window ID="winRoleDetail" runat="server" Icon="PageWhiteText" Title="详细信息" CloseAction="Hide" Hidden="true"
        Width="500" Height="300" Layout="border"  Frame=true Modal=true Resizable="false">
        <Items>
            <ext:FormPanel ID="panelDetail" runat="server" Region="West" LabelWidth="60" AutoWidth="true" Padding="5" Frame="true">
                <Items>
                    <ext:Hidden ID="txtID" runat="server" DataIndex="Id">
                    </ext:Hidden>
                    <ext:TextField ID="txtRoleName" runat="server" FieldLabel="角色名称" Width="100" DataIndex="Rolename">
                    </ext:TextField>
                    <ext:TextField ID="txtRoleAttr" runat="server" FieldLabel="角色属性" Width="100" DataIndex="Roleattr">
                    </ext:TextField>
                    <ext:TextField ID="txtComment" runat="server" FieldLabel="备注" Width="100" DataIndex="Comment">
                    </ext:TextField>
                    <ext:Hidden ID="hidFunno" runat="server" DataIndex="Rightstring">
                    </ext:Hidden>
                </Items>
            </ext:FormPanel>
            <ext:Panel ID="panelTree" runat="server" Region="Center" Width="300" Frame="true" AutoScroll="true">
                <Items>
                    <ext:TreePanel ID="menuTree" runat="server" Header="false" AutoScroll="true" Lines="false" Collapsible="false"
                        UseArrows="false" CollapseFirst="false" ContainerScroll="true" Visible="true" RootVisible ="true" 
                        Title="菜单功能">
                        <Root>
                            <ext:TreeNode Text="菜单"></ext:TreeNode>
                        </Root>
                        <Listeners>
                            <CheckChange Fn="onNodeChange"/>
                        </Listeners>
                    </ext:TreePanel>
                </Items>
            </ext:Panel>
        </Items>
        <Buttons>
            <ext:Button ID="btnSave" runat="server" Text=" 保 存 " Icon="DatabaseSave">
                <DirectEvents>
                    <Click OnEvent="btnSave_Click" Before="onTreeSubmit();">
                        <EventMask ShowMask="true" Target="CustomTarget" CustomTarget="#{winRoleDetail}" Msg="正在保存数据，请稍后..." />
                    </Click>
                </DirectEvents>
            </ext:Button>
            <ext:Button ID="btnClose" runat="server" Text=" 关 闭 " Icon="Decline" OnClientClick="#{winRoleDetail}.hide()">
              
            </ext:Button>
        </Buttons>
    </ext:Window>
    </form>
</body>
</html>
